package com.iqiyi.dbagent.view.web;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.iqiyi.dbagent.base.utils.data.DataSourceUtil;
/**
* 
* @Title: MonitorSqlServlet.java
* @Package com.iqiyi.dbagent.view.web
* @Description: 监控sql执行,web查看
* @author wangnianming
* @date 2016年1月13日 下午4:50:49
* @version V1.0
 */
public class SqlMonitorServlet extends HttpServlet {

    private static final long serialVersionUID = 1L;

    private DataSourceUtil dataSourceOperator;

	@Override
	public void init() throws ServletException {
    	 super.init();
    	 ServletContext servletContext = this.getServletContext();   
         WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(servletContext);
         dataSourceOperator = (DataSourceUtil)ctx.getBean("dbAgentDataUtilBean");
	}

	/**
	 * The doGet method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		response.setContentType("text/html");
		PrintWriter out = response.getWriter();
		request.getSession().setAttribute("username", "myname");
		boolean createResult = false;
		boolean insertResult = false;
		boolean dropResult = false;
		out.println("{'createResult':"+createResult+",'insertResult':"+insertResult+",'dropResult':"+dropResult+"}");
		out.flush();
		out.close();
	}

    public DataSourceUtil getDataSourceOperator() {
        return dataSourceOperator;
    }

    public void setDataSourceOperator(DataSourceUtil dataSourceOperator) {
        this.dataSourceOperator = dataSourceOperator;
    }

}
